/**
 业主详情页面
 **/
(function (vc) {
    vc.extends({
        data: {
            doCopyWorkInfo: {
                viewWorkFlag: '',
                workId: "",
                wtId: '',
                workName: '',
                typeName: "",
                workCycle: "",
                startTime: "",
                endTime: "",
                createUserName: "",
                curStaffName: "",
                curCopyName: "",
                stateName: "",
                createTime: '',
                items: [],
                pathUrl: '',
                taskId: '',
                deduction: 'N',
                audit: {
                    copyId: '',
                    deductionMoney: 0.00,
                    deductionReason: '',
                    itemId: '',
                }
            }
        },
        _initMethod: function () {
            $that.doCopyWorkInfo.workId = vc.getParam('workId');
            $that.doCopyWorkInfo.audit.copyId = vc.getParam('copyId');
            if (!vc.notNull($that.doCopyWorkInfo.workId)) {
                return;
            }
            $that._loadWorkInfo();
            $that._loadWorkTaskItem();
        },
        _initEvent: function () {
            vc.on('doCopyWork', 'listWorkData', function (_info) {
                $that._loadWorkInfo();
            });
            vc.on('doCopyWork', 'notifyFile', function (_param) {
                $that.doCopyWorkInfo.audit.pathUrl = _param.realFileName;
            })
        },
        methods: {
            _loadWorkInfo: function () {
                let param = {
                    params: {
                        workId: $that.doCopyWorkInfo.workId,
                        page: 1,
                        row: 1,
                    }
                }
                //发送get请求
                vc.http.apiGet('/work.listWorkPool',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        vc.copyObject(_json.data[0], $that.doCopyWorkInfo);

                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _loadWorkTaskItem: function () {
                let param = {
                    params: {
                        taskId: $that.doCopyWorkInfo.taskId,
                        workId: $that.doCopyWorkInfo.workId,
                        page: 1,
                        row: 100,
                    }
                }
                //发送get请求
                vc.http.apiGet('/task.listWorkTaskItem',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.doCopyWorkInfo.items = _json.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _selectContent: function (_item) {
                if (_item.state != 'C') {
                    return;
                }
                $that.doCopyWorkInfo.audit.itemId = _item.itemId;
            },
            _auditSubmit: function () {
                vc.http.apiPost(
                    '/work.finishWorkCopy',
                    JSON.stringify($that.doCopyWorkInfo.audit), {
                    emulateJSON: true
                },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.toast('办理成功');
                            vc.goBack();
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            }
        }
    });
})(window.vc);